package com.event;

import com.mysqld.Mysqld;
import com.window.select;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SelectEvent implements ActionListener {
    JButton jbutton;

    @Override
    public void actionPerformed(ActionEvent e) {
        jbutton = (JButton) e.getSource();

        if (jbutton.getName() == "a") {
            try {
                if (select.aa.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入学号!", "查询页面", JOptionPane.WARNING_MESSAGE);
                } else if (Mysqld.select1number()) {
                    FunctionEvent.select.dispose();
                    Mysqld.show2StuInfo();
                } else {
                    JOptionPane.showMessageDialog(null, "学号不存在!", "查询页面", JOptionPane.WARNING_MESSAGE);
                }

            } catch (Exception e1) {

            }
        }

        if (jbutton.getName() == "b") {
            try {
                if (select.bb.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入性别!", "查询页面", JOptionPane.WARNING_MESSAGE);
                } else {
                    FunctionEvent.select.dispose();
                    Mysqld.show5StuInfo();
                }

            } catch (Exception e1) {
            }
        }
        if (jbutton.getName() == "c") {
            try {
                if (select.cc.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入班级号!", "查询页面", JOptionPane.WARNING_MESSAGE);
                } else if (Mysqld.selectgrade()) {
                    FunctionEvent.select.dispose();
                    Mysqld.show3StuInfo();
                } else {
                    JOptionPane.showMessageDialog(null, "班级不存在!", "查询页面", JOptionPane.WARNING_MESSAGE);
                }

            } catch (Exception e1) {

            }
        }
        if (jbutton.getName() == "d") {
            try {
                if (select.dd.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入年龄!", "查询页面", JOptionPane.WARNING_MESSAGE);
                } else if (Mysqld.selectage()) {
                    FunctionEvent.select.dispose();
                    Mysqld.show4StuInfo();
                } else {
                    JOptionPane.showMessageDialog(null, "没有该年龄的学生!", "查询页面", JOptionPane.WARNING_MESSAGE);
                }
            } catch (Exception e1) {
            }
        }
    }
}
